//
//  ZBBContentListenNewsOrdinaryCell.m
//  沙哈拉FM
//
//  Created by dllo on 15/11/6.
//  Copyright © 2015年 S1mpl3. All rights reserved.
//

#import "ZBBContentListenNewsOrdinaryCell.h"
#import "TwoToOne.h"
#import "ZBBRecomendCell.h"
#import "S1mpl3MoreRecommend.h"
#import "TabBarController.h"
#import "UIImageView+WebCache.h"
#import "S1mpl3AlbumViewController.h"
@implementation ZBBContentListenNewsOrdinaryCell

-(instancetype)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.minimumLineSpacing = 0;
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) collectionViewLayout:flowLayout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_collectionView];
        [_collectionView registerClass:[ZBBRecomendCell class] forCellWithReuseIdentifier:@"identifiter"];
       
       
    }
    return self;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return _dataSourceArray.count;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath

{
    return CGSizeMake(self.frame.size.width, 90);
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ZBBRecomendCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"identifiter" forIndexPath:indexPath];
    
    cell.model = _dataSourceArray[indexPath.row];
    
    return cell;


}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
         
    S1mpl3AlbumViewController *lvc = [[S1mpl3AlbumViewController alloc]init];
    
    lvc.albumId = [_dataSourceArray[indexPath.row] albumId];
    
    [self.nav pushViewController:lvc animated:YES];
}
-(void)setString:(NSString *)string

{
    _string = string;
}
-(void)setDic:(NSDictionary *)dic
{
    _dataSourceArray = [NSMutableArray array];
    NSString *urlString = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=%@&categoryId=%@&device=android&pageId=1&pageSize=20&status=0&tagName=%@", _string,[dic objectForKey:@"category_id"], [dic objectForKey:@"tname"]];
    
   
     [TwoToOne getDataByString:urlString BodyString:nil WithDataBlock:^(id data) {
         NSArray *array = [data objectForKey:@"list"];
         
      
         for (NSDictionary *dic in array) {
             S1mpl3MoreRecommend *model = [[S1mpl3MoreRecommend alloc]init];
             [model setValuesForKeysWithDictionary:dic];
             [_dataSourceArray addObject:model];
         }
         [_collectionView reloadData];
         
         
    }];
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
